#!/bin/bash
#

##nginx控制脚本常用操作，start启动，stop关闭，reload重新加载配置文件，restart重启，status查看状态
if [ -z $1 ]; then
    echo "帮助(请输入参数)：$0 <start|stop|reload|restart|status>"
    exit 25
fi

nginx=/usr/local/nginx/sbin/nginx
nginx_pid_file=/usr/local/nginx/logs/nginx.pid

case $1 in
    start)
	$nginx
	if [ $? -eq 0 ]; then
	    echo "nginx启动成功"
	else
	    echo "nginx启动失败"
	fi
	;;
    stop)
	$nginx -s stop
	;;
    reload)
	kill -HUP $(cat ${nginx_pid_file})
	;;
    restart)
	$nginx -s stop
	sleep 1
	$nginx
	;;
    status)
	if [ -f $nginx_pid_file ]; then
	    echo "nginx(PID:$(cat ${nginx_pid_file})) is running"
	else
	    echo "nginx is stopped"
	fi
	;;
    *)
	echo "帮助(请输入参数)：$0 <start|stop|reload|restart|status>"
	;;
esac


